<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateUser extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
      $table = $this->table('user', [
        'engine' => 'InnoDB',
        'collation' => 'utf8mb4_general_ci',
        'comment' => '用户表',
      ]);
      $table->addColumn('username', 'string', [
              'limit' => 32,
              'null' => true,
              'comment' => '用户名',
            ])
            ->addColumn('password', 'string', [
              'limit' => 32,
              'null' => true,
              'comment' => '密码',
            ])
            ->addColumn('nickname', 'string', [
              'limit' => 32,
              'null' => true,
              'comment' => '昵称',
            ])
            ->addColumn('gender', 'string', [
              'limit' => 32,
              'null' => true,
              'comment' => '性别',
            ])
            ->addColumn('avatarUrl', 'string', [
              'limit' => 256,
              'null' => true,
              'comment' => '头像地址',
            ])
            ->addColumn('country', 'string', [
              'limit' => 64,
              'null' => true,
              'comment' => '国家',
            ])
            ->addColumn('province', 'string', [
              'limit' => 64,
              'null' => true,
              'comment' => '省',
            ])
            ->addColumn('city', 'string', [
              'limit' => 64,
              'null' => true,
              'comment' => '市',
            ])
            ->addColumn('openid', 'string', [
              'limit' => 64,
              'null' => true,
              'comment' => '微信openid',
            ])
            ->addColumn('session_key', 'string', [
              'limit' => 64,
              'null' => true,
              'comment' => '微信session_key',
            ])
            ->addColumn('user_info', 'text', [
              'null' => true,
              'comment' => '微信用户的完整userInfo',
            ])
            ->addColumn('encrypted_data', 'text', [
              'null' => true,
              'comment' => '微信用户解密后的encryptedData',
            ])
            ->addColumn('token', 'string', [
              'limit' => 32,
              'null' => true,
              'comment' => '临时登录凭证',
            ])
            ->addColumn('unionid', 'string', [
              'limit' => 128,
              'null' => true,
              'comment' => '微信unionid',
            ])
            ->addColumn('email', 'string', [
              'limit' => 64,
              'null' => true,
              'comment' => 'Email',
            ])
            ->addColumn('mobile', 'string', [
              'limit' => 32,
              'null' => true,
              'comment' => '手机',
            ])
            ->addColumn('group', 'text', [
              'null' => true,
              'comment' => '分组',
            ])
            ->addColumn('level', 'integer', [
              'default' => 0,
              'comment' => '用户等级',
            ])
            ->addColumn('config', 'text', [
              'null' => true,
              'comment' => '用户配置',
            ])
            ->addColumn('data', 'text', [
              'null' => true,
              'comment' => '用户附加数据',
            ])
            ->addColumn('balance', 'decimal', [
              'default' => 0,
              'precision' => 16,
              'scale' => 2,
              'comment' => '用户余额',
            ])
            ->addColumn('coin', 'decimal', [
              'default' => 0,
              'precision' => 16,
              'scale' => 2,
              'comment' => '用户币数',
            ])
            ->addColumn('points', 'integer', [
              'default' => 0,
              'comment' => '用户点数',
            ])
            ->addColumn('status', 'integer', [
              'default' => 1,
              'comment' => '状态',
            ])
            ->addColumn('remark', 'text', [
              'null' => true,
              'comment' => '备注',
            ])
            ->addColumn('create_at', 'datetime', [
              'null' => true,
              'comment' => '创建时间',
            ])
            ->addColumn('update_at', 'datetime', [
              'null' => true,
              'comment' => '更新时间',
            ])
            ->addColumn('delete_at', 'datetime', [
              'null' => true,
              'comment' => '删除时间',
            ])

            ->addIndex(['openid'], ['unique' => true])
            ->create();

    }
}
